<?php 
	class LoginAction extends Action{
		public function index(){
			$this->display();
		}

		public function login(){
			if(I('verify','','md5')!=session('verify')){
				$this->error('验证码错误!');
			}
			$uname=$_POST['username'];
			$pwd=md5($_POST['password']);
			if($user=M('user')->find(array('username'=>$uname))){
				if($pwd!=$user['password'])$this->error('密码错误!');
			}else $this->error('用户名不存在!');
			$data=array(
				'id'=>$user['id'],
				'loginip'=>get_client_ip(),
				'logintime'=>time()
				);
			M('user')->save($data);
			session('id',$user['id']);
			session('username',$uname);
			session('loginip',$user['loginip']);
			session('logintime',date('Y-m-d H:i',$user['logintime']));
			redirect(__GROUP__);
		}

		//退出登录
		public function logout(){
			session_unset();
			session_destroy();
			$this->redirect(GROUP_NAME.'/Login/index');
		}

		//验证码
		public function verify(){
			import('ORG.Util.Image');
			Image::buildImageVerify();
		}
	}